﻿using System;

namespace NazTek.Extension.Clr4
{
    /// <summary> 
    /// Extends Enum
    /// </summary> 
    /// <remarks></remarks> 
    public static class EnumExtension
    {
        /// <summary> 
        /// Gets the StringAttributeValue if any, that matches the specified key 
        /// </summary> 
        /// <param name="enumValue">The enumeration item whose string attribute is to be extracted</param> 
        /// <param name="descriptionId">The key of the collection of key/value pairs to filter the value by</param> 
        /// <param name="defaultEnumValue">The value to return when value for the specified key is unavailable</param> 
        /// <returns>The value associated with the spiecfied key</returns> 
        /// <example>
        /// <code>
        /// // context
        /// internal enum AgeGroup
        /// {
        ///     [Description("MinAge", "18")]
        ///     [Description("MaxAge", "35")]
        ///     [Description("Ages 18 to 35")]
        ///     Young,
        ///     [Description("MinAge", "36")]
        ///     [Description("MaxAge", "65")]
        ///     [Description("Ages 36 to 65")]
        ///     MiddleAged,
        ///     [Description("MinAge", "66")]
        ///     [Description("MaxAge", "100")]
        ///     [Description("Ages 66 to 100")]
        ///     Elder,
        ///     Unspecified
        /// }
        /// // usage
        /// AgeGroup.Young.GetDescription("MinAge", "N/A"); // returns "18"
        /// AgeGroup.Unspecified.GetDescription("MaxAge", "N/A"); // returns "N/A"
        /// </code>
        /// </example>
        /// <seealso cref="NazTek.Extension.Clr4.DescriptionAttribute"/>
        public static string GetDescription(this Enum enumValue, string descriptionId = null, string defaultEnumValue = null)
        {
            return enumValue.GetDescriptions().GetDescription(descriptionId, defaultEnumValue);
        }
        /// <summary>
        /// Gets custom attributes from an enum item
        /// </summary>
        /// <param name="enumValue">The enum item to get the list of custom attributes from</param>
        /// <returns>The list of custom attributes associated with the enum item, if any, otherwise null</returns>
        public static DescriptionAttributeList GetDescriptions(this Enum enumValue)
        {
            return new DescriptionAttributeList(enumValue);
        }
    }
}